import { Reducer, Effect } from 'redux';
import { getYS7Token, getLiveList } from '@/services/ys7Services';

export interface MonitorModelState {
  isMap: boolean;
  curLocation: string;
  videoList: any[];
}

interface dictionary {
  [key: string]: any;
}

export interface MonitorModelTypes {
  namespace: 'monitor';
  state: MonitorModelState;
  effects: {
    init: Effect;
  };
  reducers: {
    updateState: Reducer<MonitorModelState>;
  };
}

const MonitorModel: MonitorModelTypes = {
  namespace: 'monitor',
  state: {
    curLocation: '', //监控位置
    isMap: false, //是否为地图模式
    videoList: [],
  },

  effects: {
    *init({ payload }, { put }) {
      yield getYS7Token();
      // const videoList = yield getLiveList();
      // @ts-ignore
      console.log(window.liveStreamList);
      // @ts-ignore
      const videoList = window.liveStreamList;
      yield put({
        type: 'updateState',
        payload: {
          videoList,
        },
      });
    },
  },

  reducers: {
    updateState(state, { payload }): MonitorModelState {
      return { ...state, ...payload };
    },
  },
};

export default MonitorModel;
